home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / COPYC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  855 b   |  43 lines

  1. /* copyc.c - copy a file using read/write  */
  2. #include"stdio.h"
  3.  
  4. #define NO_FILE    (-1)
  5. #define BUF_SIZE   1024
  6. #define RD_MODE    0
  7. #define WR_MODE    0
  8.  
  9. main(argc,argv)
  10.   int     argc     ;
  11.   char    *argv[]  ;
  12.   {
  13.      int   in ,  out   ;
  14.      long  n  ;
  15.      char  buffer[BUF_SIZE] ;
  16.      int   nr ;
  17.  
  18.      if( argc < 3 )
  19.     {  printf(" USAGE - Copy1 input-file output-file \n") ;
  20.        exit (1) ;
  21.     }
  22.  
  23.      in =  open( argv[1] , RD_MODE ) ;
  24.      out=  creat(argv[2] , WR_MODE ) ;
  25.      if(   (in == NO_FILE) || (out == NO_FILE)    )
  26.     {  printf("Can't open a file") ;
  27.        exit (2) ;
  28.     }
  29.  
  30.      n    =  0L ;
  31.      nr =  read(in,buffer,BUF_SIZE) ;
  32.      while (nr > 0 )
  33.     { n   =  n  +  nr  ;
  34.       write (out,buffer,nr)  ;
  35.       nr  = read(in,buffer,BUF_SIZE)  ;
  36.     }  ;
  37.     close (in) ;
  38.     close (out);
  39.     printf(" %1d characters copied",n) ;
  40.   }
  41.  
  42.  
  43.